package com.xiaoxin.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaoxin.dubbo.mappers.BlackListMapper;
import com.xiaoxin.dubbo.mappers.UserInfoMapper;
import com.xiaoxin.model.domain.BlackList;
import com.xiaoxin.model.domain.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author xiaoxiaode
 * @date 2021-08-30-18:36
 **/

@DubboService
public class BlackListServiceImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;


    @Autowired
    private UserInfoMapper userInfoMapper;


    @Override
    public IPage<UserInfo> findByUserId(Long id, int page, int size) {
        //构建MyBatisPlus默认分页参数page
        Page pages = new Page(page, size);
        //调用分页方法,自定义sql
        IPage<UserInfo> iPage = userInfoMapper.findBlackList(pages, id);
        return iPage;
    }

    @Override
    public void deleteBlackList(Long id, Long uid) {
        QueryWrapper<BlackList> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", id);
        wrapper.eq("black_user_id", uid);
        blackListMapper.delete(wrapper);
    }
}
